package com.cal.utms.entity;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.cal.utms.logAudit.AuditLogInt;
import com.cal.utms.util.ValueConvert;

import java.util.Date;
import java.util.List;

/**
 * The persistent class for the placement_sheet database table.
 * 
 */
@Entity
@Table(name = "placement_sheet")
@NamedQuery(name = "PlacementSheet.findAll", query = "SELECT p FROM PlacementSheet p")
public class PlacementSheet implements Serializable, AuditLogInt {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Temporal(TemporalType.DATE)
	private Date date;

	private String status;

	// bi-directional many-to-one association to Fund
	@ManyToOne
	private Fund fund;

	// bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "RECORD_USER")
	private User user;

	// bi-directional many-to-one association to PlacementSheetRecord
	@OneToMany(mappedBy = "placementSheet", cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<PlacementSheetRecord> placementSheetRecords;

	public PlacementSheet() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Fund getFund() {
		return this.fund;
	}

	public void setFund(Fund fund) {
		this.fund = fund;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<PlacementSheetRecord> getPlacementSheetRecords() {
		return this.placementSheetRecords;
	}

	public void setPlacementSheetRecords(List<PlacementSheetRecord> placementSheetRecords) {
		this.placementSheetRecords = placementSheetRecords;
	}

	public PlacementSheetRecord addPlacementSheetRecord(PlacementSheetRecord placementSheetRecord) {
		getPlacementSheetRecords().add(placementSheetRecord);
		placementSheetRecord.setPlacementSheet(this);

		return placementSheetRecord;
	}

	public PlacementSheetRecord removePlacementSheetRecord(PlacementSheetRecord placementSheetRecord) {
		getPlacementSheetRecords().remove(placementSheetRecord);
		placementSheetRecord.setPlacementSheet(null);

		return placementSheetRecord;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Transient
	@Override
	public Long getLogId() {
		return ValueConvert.toLong(this.id);
	}

	@Transient
	@Override
	public String getLogDeatil() {
		StringBuilder sb = new StringBuilder();
		sb.append("Placement Sheet Id : ").append(id).append(" Date ").append(date);

		return sb.toString();
	}

}